import { Body, Param, Query } from '@nestjs/common';
import { Controller, Get, Post, Req } from '@nestjs/common';
import { AppService } from './app.service';

@Controller('/api')
export class AppController {
  constructor(private readonly appService: AppService) { }

  @Post('/users')
  async userLogin(@Req() { session }) {
    const user = await this.appService.userLogin();
    session.uid = user.id;
  }

  @Get('/weathers')
  async getWeatherInfoList(@Req() { session: { uid } }, @Query() { province, city, area }) {
    return this.appService.getWeatherInfoList({ province, city, area }, uid);
  }

  @Get('/weathers/:areaId')
  async getWeatherInfo(@Param() { areaId }) {
    return this.appService.getWeatherInfo(+areaId);
  }
  
  @Get('/areas')
  async getAreaListByName(@Query() { areaName }) {
    return this.appService.getAreaListByName(areaName);
  }

  @Post('/users/area')
  async collectArea(@Req() { session: { uid } }, @Body() { areaId }) {
    await this.appService.collectArea(uid, areaId);
  }
}
